//
//  AppDelegate.m
//  A段项目
//
//  Created by dllo on 16/1/22.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "Second.h"
#import "Third.h"
#import "Fourth.h"
#import "Fifth.h"
#import "UMSocial.h"
#import "UMSocialSinaSSOHandler.h"
#import "UMSocialWechatHandler.h"
#import "FMDatabase.h"
#import "FMDBDataHandler.h"
#import "ViewControllerForGuidePage.h"




@interface AppDelegate ()

@property (nonatomic, retain) UITabBarController *tb;

@end

@implementation AppDelegate

- (void)dealloc {
    
    [_window release];
    [_tb release];
    [super dealloc];
    
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    

#pragma mark -- 创建 fmdb 数据库.
    
    [[FMDBDataHandler shareDataBaseHandler] openDB];
    
    [[FMDBDataHandler shareDataBaseHandler] createTable];
    
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    [self.window makeKeyAndVisible];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    
    self.tb = [[UITabBarController alloc] init];
   
    self.tb.tabBar.barTintColor = [UIColor blackColor];
    
    self.tb.tabBar.tintColor = [UIColor redColor];
    
    
    [self createViewControllers];
    
#pragma mark -- 引导页
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"open"]) {
        
        self.window.rootViewController = self.tb;
        
    }else {
        
        
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"open"];
        
        ViewControllerForGuidePage *guide = [[ViewControllerForGuidePage alloc] init];
        self.window.rootViewController = guide;
        
        [guide release];
        
    }
    
    [[NSNotificationCenter defaultCenter]addObserverForName:@"GuidePage" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
        
        self.window.rootViewController = self.tb;
        
    }];
    
    
    
    [_window release];
    [_tb release];
    
    [UMSocialData setAppKey:@"56cd902d67e58ed66e0024b7"];
    
   [UMSocialWechatHandler setWXAppId:@"wxbf78c43790e8c98b" appSecret:@" 043dcf0e0fee6ce3b1d912c16adf7b6c" url:@"http://mapp.tiankong.com/share"];
    
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"1809753417" secret:@"c97e4aac8b713741a91764d6ca5518f" RedirectURL:@"http://mapp.tiankong.com/share/user.show"];
    
    
    [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToWechatSession, UMShareToWechatTimeline]];
    
    
    
    return YES;
}

- (void)createViewControllers {
    
    ViewController *firstVc = [[ViewController alloc] init];
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:firstVc];
    navi.navigationBar.backgroundColor = [UIColor blackColor];
    navi.navigationBar.barStyle = 1;
    firstVc.navigationItem.title = @"全景";
    
    firstVc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"全景" image:[UIImage imageNamed:@"home"] tag:100];
    
    Second *second = [[Second alloc] init];
    
    UINavigationController *naviSecond = [[UINavigationController alloc] initWithRootViewController:second];
    naviSecond.navigationBar.backgroundColor = [UIColor blackColor];
    naviSecond.navigationBar.barStyle = 1;

    second.navigationItem.title = @"发现";
    second.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"find"] tag:200];
    
    
    Third *third = [[Third alloc] init];
    
    UINavigationController *thirdNavi = [[UINavigationController alloc] initWithRootViewController:third];
    thirdNavi.navigationBar.backgroundColor = [UIColor blackColor];
    thirdNavi.navigationBar.barStyle = 1;

    third.navigationItem.title = @"活动";
    third.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"活动" image:[UIImage imageNamed:@"jiangbei"] tag:300];
    
    
    Fourth *fourth = [[Fourth alloc] init];
    
    UINavigationController *naviFourth = [[UINavigationController alloc] initWithRootViewController:fourth];
    naviFourth.navigationBar.backgroundColor = [UIColor blackColor];
    naviFourth.navigationBar.barStyle = 1;
    
    fourth.navigationItem.title = @"圈子";
    fourth.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"圈子" image:[UIImage imageNamed:@"quanzi"] tag:400];
    
    Fifth *fifth = [[Fifth alloc] init];
    
    UINavigationController *naviFifth = [[UINavigationController alloc] initWithRootViewController:fifth];
    naviFifth.navigationBar.backgroundColor = [UIColor blackColor];
    naviFifth.navigationBar.barStyle = 1;

    fifth.navigationItem.title = @"我";
    fifth.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"me"] tag:500];
    
    self.tb.viewControllers = @[navi,naviSecond,thirdNavi,naviFourth,naviFifth];
    
    [firstVc release];
    [navi release];
    [firstVc.tabBarItem release];
    
    [second release];
    [naviSecond release];
    [second.tabBarItem release];
    
    [third release];
    [thirdNavi release];
    [third.tabBarItem release];
    
    [fourth release];
    [naviFourth release];
    [fourth.tabBarItem release];
    
    [fifth release];
    [naviFifth release];
    [fifth.navigationItem release];
    
    
    
}




- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    
   
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"appWillEnd" object:nil];
    
    
   
   
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    
   
    
        
    
    

    
    
}

@end
